# Copyright (C) Kumo inc. and its affiliates.
# Author: Jeff.li lijippy@163.com
# All rights reserved.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https:#www.gnu.org/licenses/>.
#
###########################################################################
# below are examples, after initialization, modify it to your own.
###########################################################################
###kmcmake_example

set(FBS_FILES
        fbs/feather.fbs
        fbs/File.fbs
        fbs/Message.fbs
        fbs/Schema.fbs
        fbs/SparseTensor.fbs
        fbs/Tensor.fbs
        )

flatbuffers_generate_headers(
        TARGET nebula_flatbuffers
        INCLUDE_PREFIX "nebula/fbs"
        SCHEMAS ${FBS_FILES}
        #BINARY_SCHEMAS_DIR "${PROJECT_SOURCE_DIR}"
        FLAGS --gen-object-api --scoped-enums --gen-mutable
)


add_custom_target(
        headers ALL
        COMMENT "Collecting headers"
        COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_BINARY_DIR}/nebula/nebula_flatbuffers/nebula/fbs/feather_generated.h" "${PROJECT_SOURCE_DIR}/nebula/fbs"
        COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_BINARY_DIR}/nebula/nebula_flatbuffers/nebula/fbs/File_generated.h" "${PROJECT_SOURCE_DIR}/nebula/fbs"
        COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_BINARY_DIR}/nebula/nebula_flatbuffers/nebula/fbs/Message_generated.h" "${PROJECT_SOURCE_DIR}/nebula/fbs"
        COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_BINARY_DIR}/nebula/nebula_flatbuffers/nebula/fbs/Schema_generated.h" "${PROJECT_SOURCE_DIR}/nebula/fbs"
        COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_BINARY_DIR}/nebula/nebula_flatbuffers/nebula/fbs/SparseTensor_generated.h" "${PROJECT_SOURCE_DIR}/nebula/fbs"
        COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_BINARY_DIR}/nebula/nebula_flatbuffers/nebula/fbs/Tensor_generated.h" "${PROJECT_SOURCE_DIR}/nebula/fbs"
        DEPENDS
            "${PROJECT_BINARY_DIR}/nebula/nebula_flatbuffers/nebula/fbs/feather_generated.h"
            "${PROJECT_BINARY_DIR}/nebula/nebula_flatbuffers/nebula/fbs/File_generated.h"
            "${PROJECT_BINARY_DIR}/nebula/nebula_flatbuffers/nebula/fbs/Message_generated.h"
            "${PROJECT_BINARY_DIR}/nebula/nebula_flatbuffers/nebula/fbs/Schema_generated.h"
            "${PROJECT_BINARY_DIR}/nebula/nebula_flatbuffers/nebula/fbs/SparseTensor_generated.h"
            "${PROJECT_BINARY_DIR}/nebula/nebula_flatbuffers/nebula/fbs/Tensor_generated.h"
)

include_directories(${PROJECT_BINARY_DIR}/nebula/nebula_flatbuffers)
message(STATUS ${FBH})

file(GLOB_RECURSE C_SRC "c/*.cc")
file(GLOB_RECURSE UTIL_SRC "util/*.cc")
file(GLOB_RECURSE CORE_SRC "core/*.cc")
file(GLOB_RECURSE IPC_SRC "ipc/*.cc")
file(GLOB_RECURSE IO_SRC "io/*.cc")
file(GLOB_RECURSE ARRAY_SRC "array/*.cc")
file(GLOB_RECURSE JSON_SRC "json/*.cc")
file(GLOB_RECURSE TENSOR_SRC "tensor/*.cc")
file(GLOB_RECURSE CSV_SRC "csv/*.cc")
file(GLOB_RECURSE COMPUTE_SRC "compute/*.cc")
file(GLOB_RECURSE DATETIME_SRC "datetime/*.cc")
file(GLOB_RECURSE EXTENSION_SRC "extension/*.cc")
file(GLOB_RECURSE FU_SRC "future/*.cc")
file(GLOB_RECURSE NU_SRC "numeric/*.cc")
file(GLOB_RECURSE BP_SRC "bits/*.cc")
file(GLOB_RECURSE COM_SRC "compression/*.cc")
file(GLOB_RECURSE TRACE_SRC "trace/*.cc")
file(GLOB_RECURSE TYPES_SRC "types/*.cc")
kmcmake_cc_library(
        NAMESPACE ${PROJECT_NAME}
        NAME nebula
        SOURCES
        ${C_SRC}
        ${UTIL_SRC}
        ${DATETIME_SRC}
        ${CORE_SRC}
        ${IPC_SRC}
        ${IO_SRC}
        ${ARRAY_SRC}
        ${JSON_SRC}
        ${FU_SRC}
        ${NU_SRC}
        ${BP_SRC}
        ${TENSOR_SRC}
        ${CSV_SRC}
        ${COMPUTE_SRC}
        ${EXTENSION_SRC}
        ${COM_SRC}
        ${TRACE_SRC}
        ${TYPES_SRC}
        DEPS
        headers
        CXXOPTS
        ${KMCMAKE_CXX_OPTIONS}
        PLINKS
        ${KMCMAKE_DEPS_LINK}
        PUBLIC
)


kmcmake_cc_interface(
        NAMESPACE ${PROJECT_NAME}
        NAME version
        HEADERS
        version.h
        CXXOPTS
        ${KMCMAKE_CXX_OPTIONS}
        PUBLIC
)

kmcmake_cc_library(
        NAMESPACE nebula
        NAME nebula_testing
        SOURCES
        testing/fixed_width_test_util.cc
        testing/generator.cc
        testing/ktest_util.cc
        testing/ktest_util_test.cc
        testing/random.cc
        testing/random_test.cc
        testing/util.cc
        CXXOPTS
        ${KMCMAKE_CXX_OPTIONS}
        PLINKS
        nebula::nebula_static
        KTest::ktest
        ${KMCMAKE_DEPS_LINK}
        PUBLIC
)

#[[
kmcmake_cc_binary(
        NAMESPACE ${PROJECT_NAME}
        NAME shared_main
        SOURCES
        main.cc
        CXXOPTS
        ${KMCMAKE_CXX_OPTIONS}
        DEPS
        ${PROJECT_NAME}::foo
        LINKS
        ${KMCMAKE_DEPS_LINK}
        ${PROJECT_NAME}::foo
        PUBLIC
)
]]

###kmcmake_example